<template>
  <div class="hyydxq">
    <!-- spkart -->
    <!-- final -->
    <div class="listSearch">
      <div>
        <img src="@/assets/img/sou.png" alt="" class="sou" />
        <input type="text" v-model="params.keyWords" @keyup.enter="onSearch" placeholder="请输入关键词进行搜索" />
        <img src="@/assets/img/cha.png" alt="" @click="params.keyWords = ''" class="cha" />
      </div>
      <img src="@/assets/img/rili.png" alt="" class="rili" @click="dateShow = true" />
    </div>
    <van-calendar
      :min-date="minDate"
      :max-date="maxDate"
      v-model="dateShow"
      type="range"
      @confirm="onConfirm"
      color="#37B5B5"
    />
    <!-- 预约信息 -->
    <van-pull-refresh v-if="visible" v-model="refreshing" @refresh="onRefresh">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <van-cell v-for="(item, key) in list" :key="key" class="approvalItem content" @click="viewDetail(item.id)">
          <div class="flex-between font-14 line-height-3">
            <div class="col-999999 line-text-out text-right">
              {{ item.operationDate && item.operationDate.substring(0, 10) }}
            </div>
          </div>

          <div class="flex-between font-13 line-height-3">
            <div class="col-666666 m-r-10">
              {{ '转入养殖区域: ' + item.cultureArea + '' + item.physiologyStageShow }}
            </div>
          </div>

          <div class="flex-between font-13 line-height-3">
            <div class="col-666666 m-r-10">羊数量 (只)：{{ item.changeNum }}</div>
          </div>
          <div class="flex-between font-13 line-height-3">
            <div class="col-666666 line-text-out text-right">创建人：{{ item && item.createdByName }}</div>
          </div>
          <div class="flex-between font-13 line-height-3">
            <div class="col-666666 m-r-10 line-text-out">创建时间：{{ item.createTime }}</div>
          </div>
        </van-cell>
      </van-list>
    </van-pull-refresh>
    <temporarilyData v-else style="margin-top: 55px"></temporarilyData>
    <!-- spkart -->
    <!--    pageName="exhibition-extension-pigeonhole-details"-->
    <van-popup v-model="showPicker1" position="bottom">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        @confirm="onConfirmStartDate"
        @cancel="showPicker1 = false"
      />
    </van-popup>
  </div>
</template>

<script>
import { getValue, setValue, clearValue } from '@/utils/auth'
import { Toast, Cell, CellGroup, Popup, Picker, DatetimePicker, PullRefresh, CheckboxGroup, List, Calendar } from 'vant'
import { getHandle, postHandle } from '@/api'
import dayjs from 'dayjs'
import temporarilyData from '@/components/temporarilyData'
export default {
  components: {
    temporarilyData,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Popup.name]: Popup,
    [Picker.name]: Picker,
    [DatetimePicker.name]: DatetimePicker,
    [PullRefresh.name]: PullRefresh,
    [CheckboxGroup.name]: CheckboxGroup,
    [Toast.name]: Toast,
    [List.name]: List,
    // final
    [Calendar.name]: Calendar
  },
  data() {
    return {
      // spkart
      visible: true,
      flag: 0,
      showPicker1: false,
      currentDate: new Date(),
      startingTime: '',
      finishTime: '',
      refreshing: false,
      currentDate: new Date(),
      list: [],
      loading: false,
      finished: false,
      // final
      dateShow: false, // 日期弹出框
      minDate: new Date(2011, 1, 1),
      maxDate: new Date(2031, 12, 31),
      params: {
        page: 1,
        perPage: 10,
        startDate: '',
        endDate: '',
        houseInfoId: getValue('fzmHourseId') || '',
        keyWords: ''
      },
      params2: {
        page: 1,
        perPage: 10,
        orderBy: '',
        keyWords: '',
        startDate: '',
        endDate: ''
      }
    }
  },
  watch: {},
  created() {
    this.$bridge.register('refresh', data => {
      this.refreshing = true
      this.params.page = 1
      clearValue('earTag2d')
      clearValue('fzmSex')
      clearValue('earTag2')
      this.onLoad()
    })
  },
  mounted() {},
  methods: {
    // final
    onConfirm(date) {
      console.log(date)
      const [start, end] = date
      this.dateShow = false
      this.params.startDate = dayjs(start).format('YYYY-MM-DD')
      this.params.endDate = dayjs(end).format('YYYY-MM-DD')
      this.refreshing = true
      this.params.page = 1
      this.onLoad()
    },

    // 点击查看详情
    viewDetail(id) {
      setValue('viewBreedAreaRecord-id', id)
      this.$bridge.call('viewBreedAreaRecord')
    },
    // 列表spkart
    onRefresh() {
      this.params.page = 1
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    },
    onSearch() {
      this.params.page = 1
      this.list = []
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    },
    onLoad() {
      getHandle('/agri/api/yzbzh/breedAreaChange/queryListPage', this.params).then(res => {
        if (this.refreshing) {
          this.list = []
          this.refreshing = false
        }
        this.list = this.list.concat(res.data.rows)
        this.visible = this.list.length
        this.loading = false

        if (this.list.length >= res.data.count) {
          this.finished = true
        } else {
          this.params.page = this.params.page + 1
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .van-calendar__footer {
  height: 50px;
}
::v-deep .van-calendar__confirm {
  height: 50px;
  margin: 0;
}
.listSearch {
  display: flex;
  align-items: center;
  padding: 10px 18px;
  box-sizing: border-box;
  justify-content: space-between;
  div {
    width: 310px;
    height: 30px;
    position: relative;
    background-color: #fff;
    border-radius: 16px;
    input {
      height: 100%;
      box-sizing: border-box;
      position: absolute;
      left: 28px;
      width: calc(100% - 50px);
    }
    img {
      width: 12px;
      height: 12px;
      position: absolute;
      top: 50%;
      transform: translate(0, -50%);
    }
    .sou {
      left: 10px;
    }
    .cha {
      right: 10px;
    }
  }
  .rili {
    width: 20px;
    height: 20px;
  }
}
/* spkart */
.topCeiling {
  position: fixed;
  top: 0;
  z-index: 1;
}
.topDate {
  width: 80%;
  margin: auto;
  display: flex;
  justify-content: space-between;
  > p {
    font-size: 15px;
    &:first-child {
      width: 40%;
    }
    &:last-child {
      width: 40%;
    }
  }
}
.topCeiling {
  position: fixed;
  top: 0;
  z-index: 1;
}
.topDate {
  width: 80%;
  margin: auto;
  display: flex;
  justify-content: space-between;
  > p {
    font-size: 15px;
    &:first-child {
      width: 40%;
    }
    &:last-child {
      width: 40%;
    }
  }
}
.van-field__control {
  border: 0 !important;
}
.content {
  //   border-bottom: 1px solid #eee;
  padding: 10px 15px;
}
/* final */
.approvalItem {
  margin-top: 0px;
  margin-bottom: 10px;
}
</style>
